﻿using HalconDotNet;
using Halcon二次开发.View.结果分析工具;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Halcon二次开发.Controller.结果分析工具
{
    public class AnalyseControl
    {
        //输入参数
        public List<double> HideIntputArrays=new List<double>();


        //输出结果
        public List< bool> HideOutputResults = new List<bool>();
        /// <summary>
        /// 窗体结果分析对象
        /// </summary>
        private AnalyseResultForms analyseResultForms;
        public AnalyseControl(AnalyseResultForms analyseResultForms)
        {
            this.analyseResultForms = analyseResultForms;
        }

        public AnalyseControl()
        {
        }

        public void Run()
        {
            HideOutputResults.Clear();
            if (HideIntputArrays != null && HideIntputArrays.Count > 0)
            {
                double Min = (double)analyseResultForms.numericUpDown1.Value;
                double Max = (double)analyseResultForms.numericUpDown2.Value;
                if (Min < Max)
                {
                    analyseResultForms.dataGridView1.Rows.Clear();
                    for (int i = 0; i < HideIntputArrays.Count; i++)
                    {
                        DataGridViewRow r = new DataGridViewRow();
                        r.CreateCells(analyseResultForms.dataGridView1);

                        r.Cells[0].Value = i;
                        r.Cells[1].Value = DateTime.Now.ToString("HH时mm分ss秒fff毫秒");
                        r.Cells[2].Value = HideIntputArrays[i];
                        if (HideIntputArrays[i] > Min && HideIntputArrays[i] < Max)
                        {
                            HideOutputResults.Add(true);
                            //写入文件夹
                            r.Cells[3].Value = "OK";
                        }
                        else
                        {
                            HideOutputResults.Add(false);
                            //写入文件夹
                            r.Cells[3].Value = "NG";
                        }
                        analyseResultForms.dataGridView1.Rows.Add(r);
                    }
                }
                else throw new Exception("参数上下限错误");
            }
            else throw new Exception("分析工具没有得到数据");
        }
        public  void HardRun(AnalyseResultForms analyseResultForms, List<double> HideIntputArrays,ref List<bool> HideOutputResults)
        {
            HideOutputResults = new List<bool>();
            if (HideIntputArrays != null && HideIntputArrays.Count > 0)
            {
                double Min = (double)analyseResultForms.numericUpDown1.Value;
                double Max = (double)analyseResultForms.numericUpDown2.Value;
                if (Min < Max)
                {
                    for (int i = 0; i < HideIntputArrays.Count; i++)
                    {
                        if (HideIntputArrays[i] > Min && HideIntputArrays[i] < Max)
                        {
                            HideOutputResults.Add(true);
                            //写入文件夹
                        }
                        else
                        {
                            HideOutputResults.Add(false);
                        }
                    }
                }
                else throw new Exception("参数上下限错误");
            }
            else throw new Exception("分析工具没有得到数据");
        }
    }
}
